<?php
/** 
 * $Source: /cvsroot/pn-commerce/pn-commerce/pntemplates/plugins/function.pncFormValidate.php,v $
 * $Author: pcornelissen $
 * $Revision: 1.3 $
 * $Date: 2003/12/08 12:09:47 $
 *
 * Type: Function
 *
 * Purpose:   creates a javscript snippet for form validation
 * @param   Field - field to validate
 * @param   Message - constant to show as error message
 * @param   FieldType - input, drowdown (default input)
 * @return string
 */
function smarty_function_pncFormValidate($params, &$smarty)
{
    extract( $params );
    if( !$Field )
    {  
        return "*** error: missing parameter 'Field' ***";
    }
    if( !$Message )
    {
        return "*** error: no message defined ***";
    }
    $temp = "";
    switch ($FieldType)
    {
        case "dropdown":
                $temp .= "if(form.$Field.options[0].selected == true)\n";
                break;
        case "input":
        default:
                $temp .= "if(form.$Field.value == \"\")\n";
                break;
    }
    $temp .= "{\n";
    $temp .= "    alert(\""._PNC_MISSINGVALUE.":\\n\\n".constant( $Message)."\");\n";
    $temp .= "    form.$Field.focus();\n";
    $temp .= "    return false;\n";
    $temp .= "}\n";
 	return $temp;
}

?>
